package com.thwj.project.biz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.thwj.common.annotation.Log;
import com.thwj.common.core.controller.BaseController;
import com.thwj.common.core.domain.AjaxResult;
import com.thwj.common.core.page.TableDataInfo;
import com.thwj.common.enums.BusinessType;
import com.thwj.common.utils.poi.ExcelUtil;
import com.thwj.project.biz.domain.ActivityChatroom;
import com.thwj.project.biz.service.IActivityChatroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 活动聊天室Controller
 *
 * @author generate
 * @date 2023-07-13
 */
@RestController
@RequestMapping("/biz/chatroom")
public class ActivityChatroomController extends BaseController {
    @Autowired
    private IActivityChatroomService activityChatroomService;

/**
 * 查询活动聊天室列表
 */
@PreAuthorize("@ss.hasPermi('biz:chatroom:list')")
@GetMapping("/list")
    public TableDataInfo list(ActivityChatroom activityChatroom) {
        startPage();
        List<ActivityChatroom> list = activityChatroomService.list(new QueryWrapper<>(activityChatroom));
        return getDataTable(list);
    }

    /**
     * 导出活动聊天室列表
     */
    @PreAuthorize("@ss.hasPermi('biz:chatroom:export')")
    @Log(title = "活动聊天室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityChatroom activityChatroom) {
        List<ActivityChatroom> list = activityChatroomService.list(new QueryWrapper<>(activityChatroom));
        ExcelUtil<ActivityChatroom> util = new ExcelUtil<ActivityChatroom>(ActivityChatroom. class);
        util.exportExcel(response, list, "活动聊天室数据");
    }

    /**
     * 获取活动聊天室详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:chatroom:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(activityChatroomService.getById(id));
    }

    /**
     * 新增活动聊天室
     */
    @PreAuthorize("@ss.hasPermi('biz:chatroom:add')")
    @Log(title = "活动聊天室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityChatroom activityChatroom) {
        return toAjax(activityChatroomService.save(activityChatroom));
    }

    /**
     * 修改活动聊天室
     */
    @PreAuthorize("@ss.hasPermi('biz:chatroom:edit')")
    @Log(title = "活动聊天室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityChatroom activityChatroom) {
        return toAjax(activityChatroomService.updateById(activityChatroom));
    }

    /**
     * 删除活动聊天室
     */
    @PreAuthorize("@ss.hasPermi('biz:chatroom:remove')")
    @Log(title = "活动聊天室", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(activityChatroomService.removeByIds(Arrays.asList(ids)));
    }
}
